package david.java.practice.test;

import java.util.*;

/**
 * @Description:
 * @Author: ZhaoDawei
 * @Date: Create in 10:35 上午 2022/11/2
 */
public class LC_0046_全排列 {

    static List<List<Integer>> RESULT = new ArrayList<>();

    public static void main(String[] args) {

        int[] ints = {1, 2, 3};
        boolean[] used = new boolean[ints.length];
        // recursive(ints, used, new ArrayDeque<>(), ints.length, 0);
        recursive(ints, used, new ArrayDeque<>(), 2, 0);

        System.out.println(RESULT);

    }

    private static void premute(int[] array) {

    }

    private static void recursive(int[] array, boolean[] used, Deque<Integer> deque, int length, int depth) {
        if (length == depth) {
            RESULT.add(new ArrayList<>(deque));
            return;
        }

        for (int i = 0; i < array.length; i++) {
            if (used[i]) {
                continue;
            }
            deque.addLast(array[i]);
            used[i] = true;
            recursive(array, used, deque, length, depth + 1);
            deque.pollLast();
            used[i] = false;
        }
    }
}
